<template>
	<view class="pl20r pr20r pb40r">
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				店铺名：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入店铺名"
					class="f26r h60r" v-model="newObj.name"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				启用/禁用：
			</view>
			<view class="flex1 pl20r">
				<radio-group @change="radioChange1">
					<label v-for="item in radioAry1" :key="item.value"
						class="wPer50 disInBlo teAliCenter"
					>
						<radio :value="item.value"
							:checked="item.value === newObj.type"
							color="#64aeb4" style="transform: scale(0.8)"
						 />
						{{item.radioText}}
					</label>
				</radio-group>
			</view>
		</view>
		<view class="borB1SE8e8e8">
			<view class="disFlex aliItCenter h100r">
				<view class="w160r teAliRight borR1SE8e8e8">
					轮播图：
				</view>
				<view class="flex1">
					（最多选择9张图片）
				</view>
			</view>
			<view class="p20r">
				<uni-file-picker v-model="imageValue" limit="9" @delete="fileDel1"
					@select="fileSelect1"
				></uni-file-picker>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				经度：
			</view>
			<view class="flex1 pl20r">
				<input type="digit" placeholder="请输入经度"
					class="f26r h60r" v-model="newObj.lon" disabled
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				纬度：
			</view>
			<view class="flex1 pl20r">
				<input type="digit" placeholder="请输入纬度"
					class="f26r h60r" v-model="newObj.lat" disabled
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				地址：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入地址"
					class="f26r h60r" v-model="newObj.address"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				经纬度：
			</view>
			<view class="flex1 pl20r">
				<button class="w380r f26r lh60r disInBlo backCol64aeb4 colFff"
					@click="cliOpenBtn"
				>
					打开地图选择经纬度、地址
				</button>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				城市：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入城市"
					class="f26r h60r" v-model="newObj.city"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				VIP限制：
			</view>
			<view class="flex1 pl20r">
				<input type="digit" placeholder="请输入VIP限制"
					class="f26r h60r" v-model="newObj.vip_gain"
				>
			</view>
		</view>
		<!-- <view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				会员卡折扣：
			</view>
			<view class="flex1 pl20r">
				<input type="digit" placeholder="请输入会员卡折扣"
					class="f26r h60r" v-model="newObj.card_discount"
					disabled
				>
			</view>
		</view> -->
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				茶室电话：
			</view>
			<view class="flex1 pl20r">
				<input type="number" placeholder="请输入茶室电话"
					class="f26r h60r" v-model="newObj.tel"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				茶室介绍：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入茶室介绍"
					class="f26r h60r" v-model="newObj.introduce"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				登录密码：
			</view>
			<view class="flex1 pl20r">
				<input type="password" placeholder="不改密码则不用填写"
					class="f26r h60r" v-model="psd1"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				确认密码：
			</view>
			<view class="flex1 pl20r">
				<input type="password" placeholder="不改密码则不用填写"
					class="f26r h60r" v-model="psd2"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w300r teAliRight borR1SE8e8e8">
				appid
				<text class="colC62e19">
					（慎改）
				</text>
				：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入appid"
					class="f26r h60r" v-model="newObj.appid"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w300r teAliRight borR1SE8e8e8">
				appsecret
				<text class="colC62e19">
					（慎改）
				</text>
				：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入appsecret"
					class="f26r h60r" v-model="newObj.appsecret"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w300r teAliRight borR1SE8e8e8">
				mch_id
				<text class="colC62e19">
					（慎改）
				</text>
				：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入mch_id"
					class="f26r h60r" v-model="newObj.mch_id"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w300r teAliRight borR1SE8e8e8">
				mchsecret
				<text class="colC62e19">
					（慎改）
				</text>
				：
			</view>
			<view class="flex1 pl20r">
				<input type="text" placeholder="请输入mchsecret"
					class="f26r h60r" v-model="newObj.mchsecret"
				>
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				登录手机号：
			</view>
			<view class="flex1 pl20r colCcc">
				{{userInfo.phone ? userInfo.phone : ''}}
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				茶室id：
			</view>
			<view class="flex1 pl20r col999">
				{{userInfo.id ? userInfo.id : ''}}
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				开业日期：
			</view>
			<view class="flex1 pl20r col999">
				{{userInfo.opening_date ? '礼拜' + userInfo.opening_date : ''}}
			</view>
		</view>
		<view class="disFlex aliItCenter h100r borB1SE8e8e8">
			<view class="w160r teAliRight borR1SE8e8e8">
				创建时间：
			</view>
			<view class="flex1 pl20r col999">
				{{userInfo.date ? userInfo.date : ''}}
			</view>
		</view>
		<button class="w710r lh80r teAliCenter borRad10r col4f80e3 bor1S4f80e3 mAuto mt40r f26r"
			@click="cliReviseBtn"
		>
			提交修改信息
		</button>
		<view @click="cliOutLogin"
			class="w710r lh80r teAliCenter borRad10r colC62e19 bor1SC62e19 mAuto mt40r"
		>
			退出当前账号
		</view>
	</view>
</template>
<script>
import { inquiryToLogin, pathToBase64 } from '@/utils/utils.js'
import { updateTeaInfotoB, apiUploadBase64Pic } from '@/utils/api.js'
import { baseUrl } from '@/utils/request'
export default {
	data() {
		return {
			baseUrl,
			token: '',
			radioAry1: [
				{value: '1', radioText: '启用'},
				{value: '2', radioText: '禁用'}
			],
			imageValue: [],
			newObj: {
				banner: []
			},
			userInfo: {},
			psd1: '', psd2: ''
		}
	},
	onLoad() {
		// let test = "/Public/uploadImage/20230314/17472234756.png,/Public/uploadImage/20230314/17472742063.png";
		// this.newObj.banner = test;
		// if(this.newObj.banner && this.newObj.banner != '') {
		// 	console.log('this.userInfo', this.newObj.banner)
		// 	this.newObj.banner.split(',').forEach(item => {
		// 		this.imageValue.push({
		// 			name: item,
		// 			extname: "png",
		// 			url: baseUrl + item,
		// 		})
		// 	})
		// 	console.log('baseUrl2', this.imageValue)
		// 	this.$forceUpdate();
		// }
		inquiryToLogin().then(res => {
			this.token = res;
		});
		this.userInfo = uni.getStorageSync('userInfo');
		if(this.userInfo) {
			console.log('baseUrl2', this.userInfo)
			this.newObj.name = this.userInfo.name;
			this.newObj.type = this.userInfo.type;
			this.newObj.lon = this.userInfo.lon;
			this.newObj.lat = this.userInfo.lat;
			this.newObj.city = this.userInfo.city;
			this.newObj.address = this.userInfo.address;
			this.newObj.vip_gain = this.userInfo.vip_gain;
			this.newObj.card_discount = this.userInfo.card_discount;
			this.newObj.tel = this.userInfo.tel;
			this.newObj.introduce = this.userInfo.introduce;
			this.newObj.banner = this.userInfo.banner;
			this.newObj.appid = this.userInfo.appid;
			this.newObj.appsecret = this.userInfo.appsecret;
			this.newObj.mch_id = this.userInfo.mch_id;
			this.newObj.mchsecret = this.userInfo.mchsecret;
			if(this.newObj.banner && this.newObj.banner != '') {
				console.log('this.userInfo', this.newObj.banner)
				this.newObj.banner.split(',').forEach(item => {
					this.imageValue.push({
						name: item,
						extname: "png",
						url: baseUrl + item,
					})
				})
			}
		}
	},
	methods: {
		radioChange1(evt) {
			this.newObj.type = evt.detail.value;
		},
		fileSelect1(eee) {
			pathToBase64(eee.tempFilePaths[0]).then(res1 => {
				apiUploadBase64Pic({
					token: this.token, base64: res1
				}).then(res2 => {
					let newAry = [];
					if(this.newObj.banner && this.newObj.banner != '') {
						newAry = this.newObj.banner.split(',');
					}
					newAry.push(res2.data);
					this.newObj.banner = newAry.join();
					console.log('this.newObj', this.newObj)
				})
			})
		},
		fileDel1(eee) {
			let newAry = this.newObj.banner.split(',');
			newAry.forEach((item, index) => {
				if(item == eee.tempFile.name) {
					newAry.splice(index, 1)
				}
			})
			this.newObj.banner = newAry.join();
			console.log('this.newObj.banner', this.newObj.banner)
		},
		cliOpenBtn() {
			uni.chooseLocation({
				success: (res) => {
					console.log(22, res)
					this.newObj.lon = res.longitude;
					this.newObj.lat = res.latitude;
					this.newObj.address = res.address;
				}
			});
		},
		cliReviseBtn() {
			let postData = {};
			if(this.newObj.name != this.userInfo.name) postData.name = this.newObj.name;
			if(this.newObj.type != this.userInfo.type) postData.type = this.newObj.type;
			if(this.newObj.banner != this.userInfo.banner) postData.banner = this.newObj.banner;
			if(this.newObj.lon != this.userInfo.lon) postData.lon = this.newObj.lon;
			if(this.newObj.lat != this.userInfo.lat) postData.lat = this.newObj.lat;
			if(this.newObj.city != this.userInfo.city) postData.city = this.newObj.city;
			if(this.newObj.address != this.userInfo.address) postData.address = this.newObj.address;
			if(this.newObj.vip_gain != this.userInfo.vip_gain) postData.vip_gain = this.newObj.vip_gain;
			if(this.newObj.card_discount != this.userInfo.card_discount) postData.card_discount = this.newObj.card_discount;
			if(this.newObj.tel != this.userInfo.tel) postData.tel = this.newObj.tel;
			if(this.newObj.introduce != this.userInfo.introduce) postData.introduce = this.newObj.introduce;
			if(this.psd1 != this.psd2) {
				return uni.showToast({
					title: '两次密码不一致', icon: 'none', duration: 3000
				})
			}
			if(this.psd1 != '') postData.password = this.psd1;
			if(this.psd2 != '') postData.repassword = this.psd2;
			if(this.newObj.appid != this.userInfo.appid) postData.appid = this.newObj.appid;
			if(this.newObj.appsecret != this.userInfo.appsecret) postData.appsecret = this.newObj.appsecret;
			if(this.newObj.mch_id != this.userInfo.mch_id) postData.mch_id = this.newObj.mch_id;
			if(this.newObj.mchsecret != this.userInfo.mchsecret) postData.mchsecret = this.newObj.mchsecret;
			if(Object.keys(postData).length == 0) {
				return uni.showToast({
					title: '茶室信息没有修改', icon: 'none', duration: 3000
				});
			}
			uni.showModal({
				title: '提示', content: '确定提交修改信息？', confirmColor: '#64aeb4',
				success:res1 => {
					if (res1.confirm) {
						postData.token = this.token;
						updateTeaInfotoB(postData).then(res2 => {
							for(let index in postData) {
								if(index != 'password' && index != 'repassword' && index != 'token') {
									this.userInfo[index] = postData[index];
								}
							}
							uni.setStorageSync('userInfo', this.userInfo)
							uni.showToast({
								title: '修改成功', duration: 3000,
							})
						})
					}
				}
			})
		},
		cliOutLogin() {
			uni.showModal({
				title: '提示',
				content: '确定退出登录？',
				confirmColor: '#c62e19',
				success:res => {
					if (res.confirm) {
						uni.clearStorageSync();
						uni.navigateBack();
					}
				}
			})
		},
	}
}
</script>
<style>
</style>